#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QDebug>
#include <QDir>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    // QPushButton *button = new QPushButton(this);
    // button->setText("This is a diabled button");
    // button->setEnabled(true);//默认为true，false表示不可被点击

    // connect(ui->pushButton, &QPushButton::clicked, button, [=](){
    //     qDebug() <<"change button status";
    //     bool flag = button->isEnabled();
    //     button->setEnabled(!flag);
    // });

    // // connect(this, &Widget::MySignal1, this, &Widget::on_pushButton_1_clicked);
    // // connect(button, &QPushButton::clicked, this, &Widget::on_pushButton_1_clicked);
    // connect(ui->pushButton_3, &QPushButton::clicked, this, &Widget::on_pushButton_left_clicked);
    // connect(ui->pushButton_4, &QPushButton::clicked, this, &Widget::on_pushButton_right_clicked);
    // connect(ui->pushButton_5, &QPushButton::clicked, this, &Widget::on_pushButton_down_clicked);
    // connect(ui->pushButton_6, &QPushButton::clicked, this, &Widget::on_pushButton_up_clicked);
    // EmitSignal();
    QRect rect1 = this->geometry();
    QRect rect2 = this->frameGeometry();
    qDebug() << "Widget::rect1: " << rect1;
    qDebug() << "Widget::rect2: " << rect2;
    connect(ui->pushButton_2, &QPushButton::clicked, this, &Widget::on_pushButton_clicked);

    this->setWindowTitle("王凯");
    QString string1 = this->windowTitle();
    QPushButton *button1 = new QPushButton(string1, this);
    this->resize(1000, 1000);
    button1->move(378,500);

    // QIcon icon("../../../../c盘图片/make.png");
    // this->setWindowIcon(icon);
    // qDebug() << QDir::currentPath();

    // QIcon icon1 = this->windowIcon();
    // qDebug() <<icon1;

    QIcon icon(":/make.png");
    this->setWindowIcon(icon);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    qDebug() << "clicked button";
    QRect rect1 = this->geometry();
    QRect rect2 = this->frameGeometry();
    qDebug() << "Widget::on_pushButton_clicked::rect1: " << rect1;
    qDebug() << "Widget::on_pushButton_clicked::rect2: " << rect2;
}

void Widget::on_pushButton_1_clicked()
{
    bool flag = this->ui->pushButton->isEnabled();
    this->ui->pushButton->setEnabled(!flag);
}

void Widget::on_pushButton_up_clicked()
{
    // 修改的是图标大小
    // QRect rect = this->ui->pushButton_2->geometry();
    // rect.setY(rect.y() - 5);
    // ui->pushButton_2->setGeometry(rect);

    // 移动图标位置
    QRect rect = this->ui->pushButton_2->geometry();
    rect.setRect(rect.x(), rect.y() - 5, rect.width(), rect.height());
    ui->pushButton_2->setGeometry(rect);

    ui->pushButton_2->setGeometry(rect.x(), rect.y() - 5, rect.width(), rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    //修改的是图标大小
    // QRect rect = this->ui->pushButton_2->geometry();
    // rect.setY(rect.y() + 5);
    // ui->pushButton_2->setGeometry(rect);

    // 移动图标位置
    QRect rect = this->ui->pushButton_2->geometry();
    rect.setRect(rect.x(), rect.y() + 5, rect.width(), rect.height());
    ui->pushButton_2->setGeometry(rect);

    // ui->pushButton_2->setGeometry(rect.x(), rect.y() + 5, rect.width(), rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    //修改的是图标大小
    // QRect rect = this->ui->pushButton_2->geometry();
    // rect.setX(rect.x() - 5);
    // ui->pushButton_2->setGeometry(rect);

    // 移动图标位置
    QRect rect = this->ui->pushButton_2->geometry();
    rect.setRect(rect.x() - 5, rect.y(), rect.width(), rect.height());
    ui->pushButton_2->setGeometry(rect);

    // ui->pushButton_2->setGeometry(rect.x() - 5, rect.y(), rect.width(), rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    //修改的是图标大小
    // QRect rect = this->ui->pushButton_2->geometry();
    // rect.setX(rect.x() + 5);
    // ui->pushButton_2->setGeometry(rect);

    // 移动图标位置
    QRect rect = this->ui->pushButton_2->geometry();
    rect.setRect(rect.x() + 5, rect.y(), rect.width(), rect.height());
    ui->pushButton_2->setGeometry(rect);

    // ui->pushButton_2->setGeometry(rect.x() + 5, rect.y(), rect.width(), rect.height());
}


void Widget::EmitSignal()
{
    qDebug() << "emit signal";
    // emit MySignal1();
}

